import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

function getLocalUser (): User|null {
  try {
    return JSON.parse(localStorage.getItem('user') || 'null')
  } catch (error) {
    return null
  }
}

function setLocalUser (user: User) {
  return localStorage.setItem('user', JSON.stringify(user))
}

export default new Vuex.Store({
  state: {
    user: getLocalUser()
  },
  mutations: {
    setUser (state, user: User) {
      state.user = user
      setLocalUser(user)
    }
  },
  actions: {
  },
  modules: {
  }
})

interface User{
  user_id: string;
  access_token: string;
  refresh_token: string;
}
